from tortoise.models import Model
from tortoise import fields

class User(Model):
    id = fields.IntField(pk=True)
    username = fields.CharField(unique=True, max_length=10)
    password = fields.CharField(max_length=256)
    create_time=fields.DatetimeField(auto_now_add=True)
    role = fields.ManyToManyField("models.Roles", related_name="user")

    class Meta:
        table = 'user'

class Roles(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(unique=True, max_length=10)
    permissions = fields.ManyToManyField("models.Permissions", related_name="role")
    description = fields.TextField()
    class Meta:
        table = 'role'

class Permissions(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=10)
    rule = fields.CharField(max_length=10,default='all')
    path=fields.CharField(max_length=30)
    class Meta:
        table = 'permission'
class Drug(Model):
    id = fields.IntField(pk=True)
    name=fields.CharField(max_length=20,null=False,description="药品名称")
    supplier=fields.CharField(max_length=30,description="药品供应商",null=True)
    procuratorialUnits=fields.CharField(max_length=50,description="药品检察单位",null=True)
    efficacy=fields.CharField(max_length=500,description="药品疗效",null=True)
    book=fields.CharField(max_length=200,description="书籍",null=True)
    create_time=fields.DatetimeField(auto_now_add=True)
    class Meta:
        table="drug"